/* GUI CONVERTED from reoprp1a.p (converter v1.75) Tue Jun  5 16:00:31 2001 */
/* reoprp1a.p - CALCULATE LOAD FOR EACH PERIOD SUBPROGRAM OF reoprp01.p       */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.9.1.3 $                                                           */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 6.0         LAST MODIFIED 10/25/90    BY: SMM  *D144*            */
/* REVISION: 6.0         LAST MODIFIED 11/20/90    BY: emb  *D223*            */
/* REVISION: 7.0         LAST MODIFIED 03/01/92    BY: smm  *F230*            */
/* REVISION: 7.3         LAST MODIFIED 04/08/94    BY: pxd  *FN33*            */
/* REVISION: 7.3         LAST MODIFIED 04/14/94    BY: pxd  *FN38*            */
/* REVISION: 7.3         LAST MODIFIED 10/04/94    BY: cpp  *FR71*            */
/* REVISION: 7.2         LAST MODIFIED 03/23/95    BY: ais  *F0NT*            */
/* REVISION: 7.3         LAST MODIFIED 12/13/95    BY: jym  *G1G6*            */
/* REVISION: 8.6         LAST MODIFIED: 10/22/97   BY: ays *K14P*             */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 08/13/98   BY: *J2W6* Sandesh Mahagaokar */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.9.1.3 $    BY: Hualin Zhong  DATE: 05/30/01 ECO: *N0YY*          */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reoprp1a_p_2 "Day/Week/Month"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoprp1a_p_3 "Per Column"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

{wbrp02.i}

define shared variable interval as integer extent 14 no-undo.
define shared variable start like wr_start no-undo.
define shared variable sdate like ro_start extent 14 no-undo.
define shared variable num_intervals as integer initial 13 no-undo.
define shared variable more like mfc_logical no-undo.
define shared variable schedule like wr_qty_ord extent 14
   format "->>>,>>9" no-undo.
define shared variable complete like wr_qty_ord extent 14
   format "->>>,>>9" no-undo.
define new shared variable open_ref like wr_qty_ord extent 14
   format "->>>,>>9" no-undo.
define new shared variable load as decimal extent 14
   format "->>>,>>9" no-undo.
define shared variable wosite like wo_site no-undo.
define shared variable wrpart like wr_part no-undo.
define shared variable wrop   like wr_op   no-undo.
define shared variable worouting like wo_routing no-undo.
define shared variable wo_recno as recid.
define shared variable wr_recno as recid.
define variable i as integer.
define shared variable ending  like ro_end no-undo.
define shared variable workdays as integer extent 14
   format "->>>,>>9" no-undo.
define shared variable dwm as character
   format "!(1)" label {&reoprp1a_p_2} no-undo.
define shared variable idays as integer
   format ">>>>>9" label {&reoprp1a_p_3} no-undo.
define shared variable nonwdays as decimal no-undo.
define shared variable monthend as integer no-undo.
define shared variable overlap as integer no-undo.
define shared variable woline like wo_line no-undo.
define shared variable disp_schedule as character extent 14.
define shared variable disp_complete as character extent 14.
define shared variable disp_open_ref as character extent 14.
define shared variable scale_factor as decimal.
define shared variable footer_msg as character format "x(56)".
define shared variable prt_op_hdr like mfc_logical no-undo.
define variable op_hdr_pt_desc1 like pt_desc1 no-undo.
define variable op_hdr_pt_desc2 like pt_desc2 no-undo.
define variable op_hdr_ro_op    like ro_op    no-undo.
define variable op_hdr_ro_desc  like ro_desc  no-undo.
define variable wrlot like wr_lot no-undo.

FORM /*GUI*/           /* OPERATION HEADER LINES */
   wrpart
   op_hdr_pt_desc1   no-label
   op_hdr_pt_desc2   no-label
   wosite
   woline
   skip
   worouting
   op_hdr_ro_op
   op_hdr_ro_desc    no-label
with STREAM-IO /*GUI*/  frame op_hdr side-labels  width 132  no-attr-space.

/* SET EXTERNAL LABELS */
setFrameLabels(frame op_hdr:handle).

FORM /*GUI*/  header
   footer_msg
with STREAM-IO /*GUI*/  frame footer page-bottom no-labels width 132 no-attr-space.

find wo_mstr where recid(wo_mstr) = wo_recno.
find wr_route where recid(wr_route) = wr_recno.
wrlot = wr_lot.

repeat:

   /* COMPUTE START DATES */
   sdate[1] = today.
   {mfcsdate.i}

   /* INITIALIZE VARIABLES */
   workdays = 0.
   do i = 1 to num_intervals + 1:
      sdate[i] = max(sdate[i],today).
      if i <= num_intervals then
         interval[i] = max(sdate[i + 1] - sdate[i],0).
   end.

   /* CLEAR OUT ACCUMULATION AND PRINT ARRAYS */
   assign
      schedule = 0
      complete = 0
      open_ref = 0
      load     = 0.

   do i = 1 to 14:
      assign
         disp_schedule = "       0".
         disp_complete = "       0".
         disp_open_ref = "       0".
   end.

   {mfcsdate.i}
   {mfcwdays.i wosite}
   assign
      workdays[1] = max(workdays[1],0)
      sdate[1]    = low_date
      more        = no.

   for each wo_mstr no-lock
   where wo_part = wrpart
         and wo_site = wosite
         and wo_line = woline
         and wo_type = "S"
         and wo_routing = worouting
         and wo_status <> "C",
         each wr_route no-lock where wr_lot = wo_lot and wr_op = wrop:

      if wr_start < sdate[num_intervals + 1] or wr_start = ?
      then do:
         do i = 1 to num_intervals:
            if (wr_start >= sdate[i] and wr_start < sdate[i + 1])
               or wr_start = ?
            then do:
               if index("RC",wr_status) = 0
                  and wr_act_run  = 0 and wr_qty_comp = 0
                  and wr_qty_rjct = 0 and wr_qty_rwrk = 0
                  then load[i] = load[i] + wr_setup.
               if wr_status <> "C" then
                  load[i] = load[i] + wr_run
                          * max(wr_qty_ord - wr_qty_comp - wr_qty_rjct,0).

               assign
                  schedule[i] = schedule[i] + wr_qty_ord
                  complete[i] = complete[i] + min(wr_qty_comp,wr_qty_ord)
                  open_ref[i] = open_ref[i] +
                                max(wr_qty_ord - wr_qty_comp - wr_qty_rjct,0).

               /* SCALE FACTOR INDICATES WHICH UNITS TO USE IN THE REPORT. */
               /* SCALE FACTOR IS 1 OR 1,000.  SELECTION OF SCALE FACTOR   */
               /* OF 1,000 ALLOWS USER TO DISPLAY LARGE VALUES THAT        */
               /* NORMALLY EXCEED THE FIELD FORMAT SIZE. THE ROUTINE BELOW */
               /* WILL TRAP VALUES > FIELD SIZE, REPLACE WITH ???'S AND    */
               /* AVOID PROGRESS ERROR                                     */
               if (schedule[i] / scale_factor) > 9999999
                  or (schedule[i] / scale_factor) < -999999
                  then disp_schedule[i] = "????????".
               else
                  disp_schedule[i] = string (schedule[i] / scale_factor,
                                             "->>>,>>9").

               if complete[i] / scale_factor > 9999999
                  or complete[i] / scale_factor < -999999
                  then disp_complete = "????????".
               else
                  disp_complete[i] = string (complete[i] / scale_factor,
                                             "->>>,>>9").

               if open_ref[i] / scale_factor > 9999999
                  or open_ref[i] / scale_factor < -999999
                  then disp_open_ref[i] = "????????".
               else
                  disp_open_ref[i] = string (open_ref[i] / scale_factor,
                                             "->>>,>>9").

            end.     /* WR_START DO */
         end.     /* DO 1 TO NUM_INTERVALS */
      end.     /* WR_DATE < S_DATE DO */
      else more = yes.
   end.    /* FOR EACH WO_MSTR, WR_ROUTE */

   view frame footer.      /* NEEDED TO PUT FOOTER FRAME INTO FOCUS */
   if page-size - line-counter < 12 then do:
      page.
      prt_op_hdr = yes.
   end.

   if prt_op_hdr = yes then do:
      prt_op_hdr = no.

      find pt_mstr no-lock where pt_part = wrpart no-error.
      if available pt_mstr then
         assign
            op_hdr_pt_desc1 = pt_desc1
            op_hdr_pt_desc2 = pt_desc2.
      else
         assign
            op_hdr_pt_desc1 = ""
            op_hdr_pt_desc2 = "".

      find ro_det no-lock where ro_routing = worouting
         and ro_op = wrop no-error.
      find wr_route no-lock where wr_lot = wrlot
         and wr_op = wrop no-error.
      if available ro_det then
         assign
            op_hdr_ro_op   = ro_op
            op_hdr_ro_desc = ro_desc.
      else
         assign
            op_hdr_ro_op   = wr_op
            op_hdr_ro_desc = wr_desc.

      display
         wrpart
         op_hdr_pt_desc1
         op_hdr_pt_desc2
         wosite
         woline
         worouting when (worouting <> "")
         wrpart    when (worouting =  "") @ worouting
         op_hdr_ro_op
         op_hdr_ro_desc
      with frame op_hdr STREAM-IO /*GUI*/ .
   end.  /* DO: PRT_OP_HDR */

   /* DISPLAY WORKDAYS, SCHEDULED, COMPLETED, OPEN QTY, AND OPEN LOAD HOURS  */
   /* SCHEDULED, COMPLETED, OPEN QTY ARE PRINTED FROM SPECIAL DISPLAY ARRAYS */
   /* AND IF REGULAR ARRAY VALUE > PRINT FORMAT X(8) DISPLAY ARRAY W/BE      */
   /* ????'S */
   display
      space(14)
      getTermLabel("PAST",8)
      sdate[2 for 12]
      skip
      space(14)
      sdate[2] - 1
      sdate[3] - 1
      sdate[4] - 1
      sdate[5] - 1
      sdate[6] - 1
      sdate[7] - 1
      sdate[8] - 1
      sdate[9] - 1
      sdate[10] - 1
      sdate[11] - 1
      sdate[12] - 1
      sdate[13] - 1
      sdate[14] - 1
      skip
      space(14)
      "-------- -------- -------- -------- -------- --------"
      "-------- -------- -------- -------- -------- -------- --------"
      getTermLabel("WORKDAYS",13) format "x(13)"
      workdays[1 for 13]
      skip
      getTermLabel("QUANTITY_SCHEDULED",13) format "x(13)"
      disp_schedule[1 for 13]
      skip
      getTermLabel("QUANTITY_COMPLETED",13) format "x(13)"
      disp_complete[1 for 13]
      skip
      getTermLabel("QUANTITY_OPEN",13) format "x(13)"
      disp_open_ref[1 for 13]
      skip
      getTermLabel("LOAD_HOURS_OPEN",13) format "x(13)" load[1 for 13] skip
      load[1 for 13]
      skip
   with frame b no-labels width 132 no-attr-space STREAM-IO /*GUI*/ .

   {mfstrl01.i}

end. /* REPEAT AT BEGINNING OF PGM*/
/*------------------------- END OF SOURCE CODE ------------------------------*/
{wbrp04.i}
